package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import com.example.ribbon.MyRule;
import com.netflix.loadbalancer.IRule;

@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
//@RibbonClient(name="demoA", configuration=ConfigBean.class)
public class ServerDemoCApplication {

	public static void main(String[] args) {
		SpringApplication.run(ServerDemoCApplication.class, args);
	}

	@Bean                     // 注册一个具有容错功能的RestTemplate
    @LoadBalanced             // 开启负载均衡客户端
    RestTemplate restTemplate() {
        return new RestTemplate();
    }
	
	@Bean
    public IRule myRule()
    {
        return new MyRule(); //自定义负载均衡规则
    }
}
